package com.example.hrandroidapp.adapter;

import com.example.hrandroidapp.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {

	private Context mContext;
	private String[] menuArr;
	
	public ImageAdapter(Context ctx, String[] menuArr) {
		this.mContext = ctx;
		this.menuArr=menuArr;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return menuArr.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return menuArr[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View gridView;

        if (convertView == null) {

            gridView = new View(mContext);

            gridView = inflater.inflate(R.layout.grid_menu, null);

            ImageView imageView = (ImageView) gridView.findViewById(R.id.menu_image);
            imageView.setBackgroundResource(getImageDrawable(position)); 
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(5, 5, 5, 5);

            TextView textView = (TextView) gridView.findViewById(R.id.menu_name);
            textView.setText(menuArr[position]);

        } else {
            gridView = (View) convertView;
        }

        return gridView;
	}
	
	private int getImageDrawable(int position) {
		switch(position) {
		case 0:
			return R.drawable.leave; 
			
		case 1:
			return R.drawable.attendance; 
			
		case 2:
			return R.drawable.calendar; 
			
		case 3:
			return R.drawable.overtime;
			
		default: 
			return R.drawable.ic_launcher;
		}
	}

}
